package shared.config

trait Configuration {

  @volatile private var listeners: List[ (Configuration, String) => Unit ] = Nil
  
  protected def propertyChanged(name: String) = {
    listeners.foreach {  _(this, name)  }
  }
  
  def addCallback(f: (Configuration, String) => Unit) {
    synchronized {
      listeners = f :: listeners 
    }
  }
  
  def addCallback(f: Configuration => Unit) {
    addCallback{ (c: Configuration, n: String) => f(c)}
  }
  
  def addCallback(f: () => Unit) {
    addCallback{ (c: Configuration, n: String) => f()}
  }

  private var _chan: String = "SHARED"
  
  def channelName = _chan 
  def channelName_=(s: String) = {
    _chan = s
    propertyChanged("channelName")
  }
  
}
